#!/usr/bin/env python
from pyssdb import Client

__all__ = ["DatabaseManager"]


class DatabaseManager:
    supported_db_type = ['ssdb']

    def __init__(self, db_type='ssdb', *args, **kwargs):
        self.host = None
        self.port = None
        self.db_type = db_type
        self._timeout = kwargs.get('db_setting', {}).get('timeout')
        self.__dict__.update(kwargs.get('db_setting', {}))
        
    def __repr__(self):
        return 'type:<{}>,{}:{}'.format(self.db_type, self.host, self.port)

    def connect(self):
        if self.db_type not in self.supported_db_type:
            raise Exception(f'暂不支持{self.db_type}存储类型')

        ssdb_client = Client(self.host, int(self.port), socket_timeout=self._timeout)
        return ssdb_client
